var article_fields = new Array();
article_fields['required'] = new Array('author','title','journal','year');
article_fields['optional'] = new Array('volume','number','pages','month','note','key');
var book_fields = new Array();
book_fields['required'] = new Array('author','editor','title','publisher','year');
book_fields['optional'] = new Array('volume','series','address','edition','month','note','key','pages');
var booklet_fields = new Array();
booklet_fields['required'] = new Array('title');
booklet_fields['optional'] = new Array('author','howpublished','address','month','year','note','key');
var conference_fields = new Array();
conference_fields['required'] = new Array('author','title','booktitle','year');
conference_fields['optional'] = new Array('editor','pages','organization','publisher','address','month','note','key');
var inbook_fields = new Array();
inbook_fields['required'] = new Array('author','editor','title','chapter','pages','publisher','year');
inbook_fields['optional'] = new Array('volume','series','address','edition','month','note','key');
var incollection_fields = new Array();
incollection_fields['required'] = new Array('author','title','booktitle','year');
incollection_fields['optional'] = new Array('editor','pages','organization','publisher','address','month','note','key');
var inproceedings_fields = new Array();
inproceedings_fields['required'] = new Array('author','title','booktitle','year');
inproceedings_fields['optional'] = new Array('editor','pages','organization','publisher','address','month','note','key');
var manual_fields = new Array();
manual_fields['required'] = new Array('title');
manual_fields['optional'] = new Array('author','organization','address','edition','month','year','note','key');
var mastersthesis_fields = new Array();
mastersthesis_fields['required'] = new Array('author','title','school','year');
mastersthesis_fields['optional'] = new Array('address','month','note','key');
var misc_fields = new Array();
misc_fields['required'] = new Array();
misc_fields['optional'] = new Array('author','title','howpublished','month','year','note','key');
var phdthesis_fields = new Array();
phdthesis_fields['required'] = new Array('author','title','school','year');
phdthesis_fields['optional'] = new Array('address','month','note','key');
var proceedings_fields = new Array();
proceedings_fields['required'] = new Array('title','year');
proceedings_fields['optional'] = new Array('editor','publisher','organization','address','month','note','key');
var techreport_fields = new Array();
techreport_fields['required'] = new Array('author','title','institution','year');
techreport_fields['optional'] = new Array('type','number','address','month','note','key');
var unpublished_fields = new Array();
unpublished_fields['required'] = new Array('author','title','note');
unpublished_fields['optional'] = new Array('month','year','key');

var all_fields = new Array('address','annote','author','booktitle','chapter','crossref','edition','editor','eprint','howpublished','institution','journal','key','month','note','number','organization','pages','publisher','school','series','title','type','url','volume','year');
var all_fields2 = new Array();
all_fields2['required'] = new Array();
all_fields2['optional'] = new Array('address','annote','author','booktitle','chapter','crossref','edition','editor','eprint','howpublished','institution','journal','key','month','note','number','organization','pages','publisher','school','series','title','type','url','volume','year');

var fieldDisplay = new Array();

function hideFields(fields) {
  var reqFields = fields['required'];
  var optFields = fields['optional'];
  var n = all_fields.length;
  var element;
  for(var i = 0; i < n; i++) {
    var id = 'edit-'+all_fields[i]+'-wrapper';
    if(reqFields.indexOf(all_fields[i]) != -1) {
      element = document.getElementById(id);
      if(element != null) {
        if(element.className.search('bibtex-required') == -1) element.className += ' bibtex-required';
        element.className = element.className.replace(' bibtex-optional','');
      }
    } else if(optFields.indexOf(all_fields[i]) != -1) {
      
      element = document.getElementById(id);
      if(element != null) {
        if(element.className.search('bibtex-optional') == -1) element.className += ' bibtex-optional';
        element.className = element.className.replace(' bibtex-required','');
      }
    } else {
      element = document.getElementById(id);
      if(element != null) {
        if(reqFields.indexOf(all_fields[i]) != -1) {
          if(element.className.search('bibtex-required') == -1) element.className += ' bibtex-required';
        } else if(optFields.indexOf(all_fields[i]) != -1) {
          if(element.className.search('bibtex-optional') == -1) element.className += ' bibtex-optional';
        } else {
          element.className = element.className.replace(' bibtex-required','');
          element.className = element.className.replace(' bibtex-optional','');
        }
        
      }
    }
  }
}
function changeFields(value) {
  value = value.toLowerCase();
  switch(value) {
    case 'article':
      hideFields(article_fields);
      break;
    case 'book':
      hideFields(book_fields);
      break;
    case 'booklet':
      hideFields(booklet_fields);
      break;
    case 'conference':
      hideFields(conference_fields);
      break;
    case 'inbook':
      hideFields(inbook_fields);
      break;
    case 'incollection':
      hideFields(incollection_fields);
      break;
    case 'inproceedings':
      hideFields(inproceedings_fields);
      break;
    case 'manual':
      hideFields(manual_fields);
      break;
    case 'mastersthesis':
      hideFields(mastersthesis_fields);
      break;
    case 'misc':
      hideFields(misc_fields);
      break;
    case 'phdthesis':
      hideFields(phdthesis_fields);
      break;
    case 'proceedings':
      hideFields(proceedings_fields);
      break;
    case 'techreport':
      hideFields(techreport_fields);
      break;
    case 'unpublished':
      hideFields(unpublished_fields);
      break;
    default:
      hideFields(all_fields2);
      break;
  }
}